export const setStorage = (key, value) => {
    try {
        wx.setStorageSync(key, value)
    } catch (error) {
        console.log(`存储${key}失败`, error);
    }
}

export const getStorage = (key) => {
    try {
        // 读取到的值赋值给value
        const value = wx.getStorageSync(key)
        //    如果获取到了值就把值返回出去
        if (value) {
            return value
        }
    } catch (error) {
        console.log(`读取${key}失败`, error);
    }
}

export const removeStorage = (key) => {
    try {
        wx.removeStorageSync(key)
    } catch (error) {
        console.log(error);
    }
}

export const clearStorage = () => {
    try {
        wx.clearStorageSync()
    } catch (error) {
        console.log(error);
    }
}
//异步存储读取操作
export const syncSetstorage = (key, data) => {
    return new Promise((resolve) => {
        wx.setStorage({
            key,
            data,
            complete(res) {
                resolve(res)
            }
        })
    })
}

export const asyncGetstorage = (key) => {
    return new Promise((resolve) => {
        wx.setStorage({
            key,

            complete(res) {
                resolve(res)
            }
        })
    })
}


export const asyncRemoveStorage = (key) => {
    return new Promise((resolve) => {
        wx.removeStorage({
            key,
            complete(res) {
                resolve(res)
            }
        })
    })
}

export const asyncClearStorage = (key) => {

    return new Promise((resolve) => {
        wx.clearStorage({
            key,
            complete(res) {
                resolve(res)
            }
        })
    })

}